<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>bmob</title>
	<script src="bmob-min.js"></script>
</head>
<body>
   <div>
   	    <table>
   	    	 <tr>
   	    	 	 <td>姓名</td>
   	    	 	 <td><input type="text" id="xing"></td>
   	    	 </tr>
   	    	 <tr>
   	    	 	<td>年龄</td>
   	    	 	<td><input type="text" id="nian"></td>
   	    	 </tr>
   	    	 <tr>
   	    	 	<td>简介</td>
   	    	 	<td><input type="text" id="jian"></td>
   	    	 </tr>
   	    </table>
   </div>
	<button id="zeng">新增一条数据</button><br><br>
	<button id="zengshu">新增一组数据</button><br><br>
	<button id="shan">删除一条数据</button><br><br>
	<button id="xiu">修改一条数据</button><br><br>
	<button id="chayi">查询一条数据</button><br><br>
	<button id="chaduo">查询多条数据</button><br>
</body>
<script>
//初始化bomb
    Bmob.initialize("dd1429775fdbc46fbb451e1cb275e50a", "58637ca5a98ce0a28d60f5307a13c419");

    var ProductList = Bmob.Object.extend("ProductList");
    //增加
    //增加一项
	document.querySelector("#zeng").onclick = function(){
           
		    var productList = new ProductList();
		    productList.set("title", "蜂蜜柚子茶");
		    productList.save(null, {
		      success: function(object) {
		        alert("create object success, object id:"+object.id);
		      },
		      error: function(model, error) {
		        alert("create object fail");
		      }
		    });
	};
	//增加数组
	document.querySelector("#zengshu").onclick = function(){
            var xing= document.querySelector("#xing").value;
            var nian= document.querySelector("#nian").value;
            var jian= document.querySelector("#jian").value;

		    var productList = new ProductList();
		    productList.set("xing",xing);
		    productList.set("nian",nian);
		    productList.set("jian",jian);

		    productList.save(null, {
		      success: function(object) {
		        alert("create object success, object id:"+object.id);
		      },
		      error: function(model, error) {
		        alert("create object fail");
		      }
		    });
	};
	//删除
	document.querySelector("#shan").onclick = function(){
           
		    var query = new Bmob.Query(ProductList);
		    query.get("90074cb34e", {
		      success: function(object) {
		        // The object was retrieved successfully.
		        object.destroy({
		          success: function(deleteObject) {
		          alert("delete success");
		          },
		          error: function(GameScoretest, error) {
		          alert("delete fail");
		          }
		        });
		      },
		      error: function(object, error) {
		        alert("query object fail");
		      }
		    });
	};
	//修改
	document.querySelector("#xiu").onclick = function(){
		    var query = new Bmob.Query(ProductList);
		    query.get("bb2ca4f21c	", {
		      success: function(object) {
		        // The object was retrieved successfully.
		        object.set("xing", "666666");
		        object.save(null, {
		          success: function(objectUpdate) {
		            alert("create object success, object score:"+objectUpdate.get("score"));
		          },
		          error: function(model, error) {
		            alert("create object fail");
		          }
		        });
		      },
		      error: function(object, error) {
		        alert("query object fail");
		      }
		    });

	};
	//查询1
	document.querySelector("#chayi").onclick = function(){

	};
	//查询多
	document.querySelector("#chaduo").onclick = function(){
           
			var query = new Bmob.Query(ProductList);
			// 查询所有数据
			query.find({
			  success: function(results) {
			    alert("共查询到 " + results.length + " 条记录");
			    // 循环处理查询到的数据
			    for (var i = 0; i < results.length; i++) {
			      var object = results[i];
			      alert(object.id + ' - ' + object.get('playerName'));
			    }
			  },
			  error: function(error) {
			    alert("查询失败: " + error.code + " " + error.message);
			  }
			});
				};




</script>
</html>